package com.example.artwindow.handler;

import com.example.artwindow.exception.UnauthorizedException;
import com.example.artwindow.result.Result;
import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

@RestControllerAdvice
public class GlobalExceptionHandler {
	@ExceptionHandler(UnauthorizedException.class)
	public Result<?> UnauthorizedException(UnauthorizedException exception){
		return Result.error(exception.getMessage(),exception.getCode());
	}
	@ExceptionHandler(IOException.class)
	public Result<?> IoException(IOException exception){
		return Result.error(exception.getMessage(),403);
	}

}
